package com.game.astd.spirit.inter;

import com.game.astd.spirit.GameUserInfoUtil;
import com.game.astd.spirit.GetUserInfoTask;
import com.game.astd.spirit.LoginTask;
import com.game.astd.spirit.TaskManager;
import com.game.astd.spirit.model.UserData;

/**
 * 任务单元
 * 
 * @author beedoorwei
 * 
 */
public abstract class TaskUnit implements Runnable
{
	public String taskDesc;
	public int gid;
	public TaskUnit a;

	public void run()
	{
		boolean needRemove = true;
		try
		{
			// 登陆任务除外
			if (this instanceof LoginTask || this instanceof com.game.astd.spirit.GetUserInfoTask)
			{
				doTask();
			} else
			{
				UserData u = GameUserInfoUtil.getUser(gid);
				// 判断是否处于登录状态
				if (u != null && u.getIsLogining())
				{
					needRemove = false;
				} else
				{
					doTask();
				}
			}
		} catch (Exception ex)
		{
			ex.printStackTrace();
		} finally
		{
			if (needRemove)
			{
				TaskManager.removeTask(this);
			}
		}
	}

	public int getGid()
	{
		return gid;
	}

	public void setGid(int gid)
	{
		this.gid = gid;
	}

	public abstract void doTask();

	public String getTaskDesc()
	{
		return taskDesc;
	}

	public void setTaskDesc(String taskDesc)
	{
		this.taskDesc = taskDesc;
	}

}
